<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
?>
<script type="text/javascript" language="javascript">
    var biayasiswaStore = createStore(false, 'mbiayasiswaStore', 
    ['id','nis','nama','kd_kelas','kelas','id_th_ajaran','tahun_ajaran','kd_biaya','biaya','biaya_dasar','biaya_dikenakan','tgl_entri','id_user'],
    '<?php echo base_url(); ?>' + 'biayasiswa/get_rows');   
     var biayasiswaStoreAll = createStore(false, 'mbiayasiswaStoreAll', 
    ['id','nis','nama','kd_kelas','kelas','id_th_ajaran','tahun_ajaran','kd_biaya','biaya','biaya_dasar','biaya_dikenakan','tgl_entri','id_user'],
    '<?php echo base_url(); ?>' + 'biayasiswa/get_rows_all');   
    var biayasiswaStoreGroup= createStoreGroup(false, 'mGbiayasiswa', ['id','nis','nama','kd_kelas','kelas','id_th_ajaran','tahun_ajaran','kd_biaya','biaya','biaya_dasar','biaya_dikenakan','tgl_entri','id_user','fgroup'],
    'fgroup', '<?php echo base_url(); ?>' + 'biayasiswa/get_rows');
    var entrybiayasiswaStore = createStore(false, 'mentrybiayasiswaStore',['nis','id_th_ajaran','kd_biaya','biaya','biaya_dasar','biaya_dikenakan'],'<?php echo base_url(); ?>' + 'biayasiswa/get_rows_entry');
    var combothajaranStore = createStore(false, 'mcombothajaranStore',['id_th_ajaran','tahun_ajaran'],'<?php echo base_url(); ?>' + 'tahunajaran/get_rows_combo');
    var combothajaranStoreU = createStore(false, 'mcombothajaranStore',['id_th_ajaran','tahun_ajaran'],'<?php echo base_url(); ?>' + 'tahunajaran/get_rows_combo');
    var combobiayaStore = createStore(false, 'mcombobiayaStore',['kd_biaya','keterangan','biaya_dasar'],'<?php echo base_url(); ?>' + 'masterbiaya/get_rows_combo');
    var combobiayaStoreU = createStore(false, 'mcombobiayaStore',['kd_biaya','keterangan','biaya_dasar'],'<?php echo base_url(); ?>' + 'masterbiaya/get_rows_combo');
    var allsiswaStoreBi = createStore(false, 'mallsiswaStorePot',['nis','nama','kd_kelas','kelas'],'<?php echo base_url(); ?>' + 'datasiswa/get_rows_all');
    //==========================================================================================
    var twinsiswaStore = createStore(false, 'mtwinsiswaStore',['nis','nama','kd_kelas','kelas'],'<?php echo base_url(); ?>' + 'datasiswa/get_rows_twin');
    defineTwinSiswa_windows('Windowfindsiswa', 'Windowfindsiswa_id', twinsiswaStore, function(){			
        var sm = this.getSelectionModel();
        var sel = sm.getSelection();
        //                console.log('doublekil');
        if (sel.length > 0) {	
            Ext.getCmp('biayasiswa_nis').setValue(sel[0].get('nis'));
            Ext.getCmp('biayasiswa_nama').setValue(sel[0].get('nama'));
            Ext.getCmp('biayasiswa_kelas').setValue(sel[0].get('kelas'));                    
            Ext.getCmp('Windowfindsiswa_id').close();
            Ext.getCmp('biayasiswa_id_th_ajaran').focus();
        }
    });
    
    //===================
    function addrecord_ebis(){
        var vGrid = Ext.getCmp('gridebiayasiswa');
        //        console.log(Plant);
        var rowentryjurnal = new Writer.EntryTHD();
        var edit = vGrid.getPlugin();
        edit.cancelEdit();
        vGrid.getStore().insert(0, rowentryjurnal);
        edit.startEdit(0, 0);
    }
    setDefineWriter('Writer.EntryBIS',[
        {name:'nis',type:'string'},
        {name:'id_th_ajaran',type:'string'},
        {name:'kd_biaya',type:'string',useNull:false},
        {name:'biaya',type:'string',useNull:false},
        {name:'biaya_dasar',type:'string',useNull:false},
        {name:'biaya_dikenakan',type:'string',useNull:false},
    ]);
    
    Ext.define('Formbiayasiswa', {
        extend          : 'Ext.form.Panel',
        alias           : 'widget.biayasiswaForm',
        id              : 'Formbiayasiswa_id',
        requires        : [
            'Ext.form.Field'
        ],
        defaultType     : 'textfield',
        defaults        : {
            allowBlank: false,
            labelWidth: 130,
            labelAlign: 'right'
        },
        monitorValid: true,
        url: '<?php echo base_url(); ?>' + 'biayasiswa/update_rows',
        buttonAlign     : 'center',
        padding         : 5,
        style           : 'background-color: #fff;',
        border          : false,
        initComponent   : function(){
            this.items = [
                {
                    xtype: 'fieldset',
                    title: 'Data Siswa',
                    defaultType: 'textfield',
                    layout: 'anchor',
                    defaults: {
                        anchor: '90%',
                        labelAlign: 'right',
                        allowBlank: false,
                        labelWidth: 80
                    },
                    items: [
                        {xtype: 'twincombo'
                            ,name: 'nis'
                            ,fieldLabel: 'Nis',
                            id:'biayasiswa_nis',
                            store:twinsiswaStore,
                            menu:'Windowfindsiswa',
                            enableKeyEvents:true,
                            allowBlank:false
                            ,listeners:{
                                keyup: function(f,e,opt) { 
                                    if (e.getKey()==113){
                                        f.onTrigger1Click();
                                    }     
                                    if (e.getKey()==13){
                                        if(f.getValue().length>0){
                                            var rec=  findNis(f.getValue(), allsiswaStoreBi);
                                            if(rec){

                                                Ext.getCmp('biayasiswa_nama').setValue(rec.get('nama'));
                                                Ext.getCmp('biayasiswa_kelas').setValue(rec.get('kelas')); 
                                                Ext.getCmp('biayasiswa_id_th_ajaran').focus();
                                            }else{
                                                set_message(2,'Data Siswa Tidak Terdaftar !!!');
                                                f.setValue('');
                                            }
                                        };
                                    }
                                }
                            }
                        }      
                        ,{
                            name: 'nama',
                            id: 'biayasiswa_nama',
                            fieldLabel: 'Nama Siswa',
                            maxLength:50,
                            //                                    flex: 2,
                            labelWidth: 80,
                            //                        width:200,
                            //                                    margins: '0 0 0 5',
                            emptyText: 'Nama Siswa',
                            allowBlank: true
                            ,readOnly:true
                            //                                    ,
                            //                                    tooltip: 'Field tidak boleh kosong',
                            //                                    afterLabelTextTpl: required_css
                        },{
                            name: 'kelas',
                            id: 'biayasiswa_kelas',
                            fieldLabel: 'Kelas',
                            maxLength:50,
                            //                                    flex: 2,
                            labelWidth: 80,
                            //                        width:200,
                            //                                    margins: '0 0 10 0'  ,  
                            emptyText: 'Kelas',
                            allowBlank: true
                            ,readOnly:true
                        },{
                            xtype:'combo',
                            name: 'id_th_ajaran',
                            id: 'biayasiswa_id_th_ajaran',
                            fieldLabel: 'Tahun Ajaran',                                    
                            labelWidth: 80,
                            emptyText: 'Tahun Ajaran'
                            ,mode:'local',
                            store: combothajaranStore,
                            valueField: 'id_th_ajaran',
                            displayField: 'tahun_ajaran',
                            typeAhead: true,
                            triggerAction: 'all',                    
                            allowBlank: false,
                            editable: false  
                            ,listeners:{
                                select:function(cmb,rec){
                                    console.log(rec[0].get('tahun_ajaran'));
                                }
                            }
                        },
                                
                    ]
                },
                {
                    xtype:'grid',
                    id:'gridebiayasiswa',
                    height:250,
                    store: entrybiayasiswaStore,
                    stripeRows: true,
                    anchor:'100%',
                    //                        loadMask: true,
                    stateful:true,
                    stateId:'stateGridebisiswa',   
                    selModel:Ext.create('Ext.selection.RowModel',{
                        listeners:{
                            selectionchange: function( scope, selected, eOpts ){                                
                                //                                Ext.getCmp('gridebiayasiswa').down('#delete').setDisabled(selected.length === 0);
                            }
                        }
                    })
                    //                        selType: 'cellmodel',
                    ,plugins: [
                        Ext.create('Ext.grid.plugin.RowEditing', {
                            clicksToMoveEditor: 1,
                            autoCancel: false,
                            listeners: {
                                cancelEdit: function(rowEditing, context) {
                                    // Canceling editing of a locally added, unsaved record: remove it
                                        
                                        
                                        
                                        
                                    if (context.record.phantom) {
                                        var rp=context.record;
                                        if(rp.data.kd_biaya==""){
                                            Ext.getCmp('gridebiayasiswa').getStore().remove(context.record);
                                        }
                                            
                                    }
                                }
                            }
                        })
                        //                            Ext.create('Ext.grid.plugin.CellEditing', {
                        //                                clicksToEdit: 1
                        //                            })
                    ],
                    columns:[
                        {
                            xtype: 'actioncolumn',
                            width: 30,
                            sortable: false,
                            menuDisabled: true,
                            items: [{
                                    iconCls: 'icon-delete',
                                    tooltip: 'Delete Plant',
                                    scope: this,
                                    handler: function(){
                                        var vGrid=Ext.getCmp('gridebiayasiswa');
                                        var selection = vGrid.getView().getSelectionModel().getSelection()[0];
                                        if (selection) {
                                            vGrid.getStore().remove(selection);                                            
                                        }
                                        
                                    }
                                }]
                        },
                        {
                            
                            hidden:true,
                            text: 'nis',
                            dataIndex: 'nis',
                            sortable: false,
                            align:'center',
                            width: 100,
                            editor:{
                                xtype:'textfield',                                
                                id: 'ebisiswa_nis'                                
                                ,readOnly:true
                            }
                        },
                        {
                            
                            hidden:true,
                            text: 'id_th_ajaran',
                            dataIndex: 'id_th_ajaran',
                            sortable: false,
                            align:'center',
                            //                                flex:1,
                            width: 100,
                            editor:{
                                xtype:'textfield',                                
                                id: 'ebisiswa_id_th_ajaran'                                
                                ,readOnly:true
                            }
                        },
                        {
                            text: 'Biaya',
                            dataIndex: 'kd_biaya',
                            sortable: false,
                            align:'center',
                            //                                flex:1,
                            width: 100,
                            editor:{
                                xtype: 'combo',                                                            
                                tooltip: 'Field tidak boleh kosong',
                                afterLabelTextTpl: required_css,
                                //                                    fieldLabel: 'Jenis Biaya',                        
                                id: 'ebisiswa_kd_biaya',
                                mode:'local',
                                store: combobiayaStore,
                                valueField: 'kd_biaya',
                                displayField: 'keterangan',
                                typeAhead: true,
                                triggerAction: 'all',                    
                                allowBlank: false,
                                editable: false,                                
                                listeners: {
                                    select:function( combo, records, eOpts ){
                                        var sexists=false;
                                        //                                        console.log(records.keterangan);
                                        entrybiayasiswaStore.each(function(node){
                                            if(node.data.kd_biaya==combo.getValue()){
                                                sexists=true;
                                            }                                            
                                        });
                                        if(sexists){
                                            set_message(2, 'Kode Biaya Sudah Terdaftar !');
                                            combo.setValue('');
                                        }else{
                                            var rec=records[0];
                                            Ext.getCmp('ebisiswa_biaya').setValue(rec.get('keterangan'));
                                            Ext.getCmp('ebisiswa_biaya_dasar').setValue(rec.get('biaya_dasar'));
                                            Ext.getCmp('ebisiswa_biaya_dikenakan').setValue(rec.get('biaya_dasar'));
                                            Ext.getCmp('ebisiswa_biaya_dikenakan').focus();
                                        }   
                                    }
                                }
                                    
                            }
                        }
                        ,{
                            //                        hidden:true,
                            text: 'Biaya',
                            dataIndex: 'biaya',
                            sortable: false,
                            align:'center',
                            
                            //                                flex:1,
                            width: 100,
                            editor:{
                                xtype:'textfield',                                
                                id: 'ebisiswa_biaya',
                                emptyText: 'Nama Biaya'                                
                                ,readOnly:true
                            }
                        }
                        ,{
                            xtype:'numbercolumn',
                            text: 'Biaya Dasar',
                            dataIndex: 'biaya_dasar',
                            sortable: false,
                            align:'right',
                            format:'0,0',                            
                            width: 100,
                            editor:{
                                xtype:'textfield',                                
                                id: 'ebisiswa_biaya_dasar',
                                align:'right'                         
                                ,readOnly:true
                            }
                        },
                        {
                            xtype:'numbercolumn',
                            flex:1,
                            text: 'Biaya Dikenakan',
                            dataIndex: 'biaya_dikenakan',
                            sortable: false,
                            align:'right',
                            format:'0,0',                            
                            width: 100,
                            editor:{
                                xtype:'numberfield',                                
                                id: 'ebisiswa_biaya_dikenakan',
                                allowBlank: false,                                                                        
                                hideTrigger: true,
                                fieldStyle: 'text-align: right;',
                                minValue: 0                                                            
                            }
                        }
                            
                    ]
                    ,tbar:[{
                            text: 'Add',
                            iconCls: 'icons-add',
                            handler: function(){
                                var vnis=Ext.getCmp('biayasiswa_nis').getValue();                               
                                if(!vnis){
                                    set_message(2, 'Nomor Induk Siswa(NIS) Belum Diisi !!!');
                                    return;
                                }
                                var vthajaran = Ext.getCmp('biayasiswa_id_th_ajaran').getValue();
                                if(vthajaran){
                                    addrecord_grideditor('gridebiayasiswa',
                                    new Writer.EntryBIS(
                                    {
                                        nis:vnis,
                                        id_th_ajaran:vthajaran,
                                        kd_biaya:'',
                                        biaya:'',
                                        biaya_dasar:0,
                                        biaya_dikenakan:0
                                    })                                    
                                );
                                }else{
                                    set_message(2, 'Tahun Ajaran Belum Diisi !!!');
                                }
                                    
                            }
                        }                       
                    ]
                }
            ];
            this.buttons = [
                {
                    text: 'Simpan',                    
                    itemId: 'simpan',
                    id:'btn_biayasiswa_simpan',
                    iconCls: 'icons-add',
                    formBind: true,
                    scope: this,
                    handler: this.submit
                },
                {
                    text: 'Batal',
                    action: 'cancel',
                    itemId: 'batal',
                    iconCls: 'cancel',
                    handler: function(){
                        this.up('window').close();
                    }
                }
            ];
            this.callParent(arguments);
        },
        submit: function(){
            if (Ext.getCmp('gridebiayasiswa').getStore().getCount()==0){
                set_message(2, 'Record Biaya Belum Diisi !!!');
                return;
            }
            var postdata=new Array();
            var strdata=Ext.getCmp('gridebiayasiswa').getStore();
            strdata.each(function(node){
                postdata.push(node.data);
            });
            var parcmd=Ext.getCmp('btn_biayasiswa_simpan').getText();
            if(parcmd === 'Simpan'){
                parcmd='insert';
            }else if(parcmd === 'Edit'){
                parcmd='update';
            }
            
            Ext.getCmp('Formbiayasiswa_id').getForm().submit({
                url: this.url,
                scope: this,               
                //                success: this.onSuccess,
                //                failure: this.onFailure,
                params: {
                    cmd: parcmd,
                    postdata:Ext.JSON.encode(postdata)
                },
                waitMsg: 'Saving Data...',
                success: function(form, action) {
                    //                    console.log(action);
                    set_message(0,action.result.msg);
                    //                    Ext.Msg.alert('Success', action.result.msg);
                    Ext.getCmp('gridbiayasiswa').store.reload(); 
                    biayasiswaStoreAll.reload();
                    Ext.getCmp('Formbiayasiswa_id').getForm().reset();
                    Ext.getCmp('Windowbiayasiswa_id').close();
                },
                failure: function(form, action) {
                    if(action.result.msg=='Session Expired') {
                        session_expired(action.result.msg);
                    }else{
                        set_message(1, action.result.msg);
                    }
                                            
                    
                }
            });
        } // eo function submit        
        ,
        showError: function(msg, title){
            title = title || 'Error';
            Ext.Msg.show({
                title: title,
                msg: msg,
                modal: true,
                icon: Ext.Msg.ERROR,
                buttons: Ext.Msg.OK,
                fn: function(btn){
                    if (btn == 'ok' && msg == 'Session Expired') {
                        window.location = '<?= site_url("auth/login") ?>';
                    }
                }
            });
        }
    });

    Ext.define('Windowbiayasiswa', {
        extend          : 'Ext.window.Window',
        title           : 'Form Edit Biaya Siswa',
        width           : 500,
        height          : 480,
        layout          : 'fit',
        autoShow        : true,
        modal           : true,
        alias           : 'widget.biayasiswaEdit',
        id              : 'Windowbiayasiswa_id',
        initComponent   : function(){
            this.items = [
                Ext.widget('biayasiswaForm')
            ];
            this.callParent(arguments);
        }

    });
    //===================one row edit
    
    Ext.define('FormUbis', {
        extend          : 'Ext.form.Panel',
        alias           : 'widget.UbisForm',
        id              : 'FormUbis_id',
        requires        : [
            'Ext.form.Field'
        ],
        defaultType     : 'textfield',
        defaults        : {
            allowBlank: false,
            labelWidth: 120,
            labelAlign: 'right',
            anchor:'90%'
            
        },
        monitorValid: true,
        url: '<?php echo base_url(); ?>' + 'biayasiswa/update_rows',
        buttonAlign     : 'center',
        padding         : 5,
        style           : 'background-color: #fff;',
        border          : false,
        initComponent   : function(){
            this.items = [    
                {
                    xtype: 'textfield'                            
                    ,name: 'id'                            
                    ,fieldLabel: 'Rec.ID',
                    id:'Ubis_id',                                    
                    emptyText: 'id',
                    allowBlank:false
                    ,readOnly:true                                    
                }      
                ,
                {
                    xtype: 'textfield'                            
                    ,name: 'nis'                            
                    ,fieldLabel: 'Nis',
                    id:'Ubis_nis',                                    
                    emptyText: 'NIS',
                    allowBlank:false
                    ,readOnly:true                                    
                }      
                ,{
                    name: 'nama',
                    id: 'Ubis_nama',
                    fieldLabel: 'Nama Siswa',
                    maxLength:50,
                    emptyText: 'Nama Siswa',
                    allowBlank: false
                    ,readOnly:true                    
                },{
                    name: 'kelas',
                    id: 'Ubis_kelas',
                    fieldLabel: 'Kelas',
                    maxLength:50,
                    emptyText: 'Kelas',
                    allowBlank: true
                    ,readOnly:true
                },{
                    xtype:'combo',
                    afterLabelTextTpl: required_css,
                    name: 'id_th_ajaran',
                    id: 'Ubis_id_th_ajaran',
                    fieldLabel: 'Tahun Ajaran',                                    
//                    labelWidth: 80,
                    emptyText: 'Tahun Ajaran'
                    ,mode:'local',
                    store: combothajaranStoreU,
                    valueField: 'id_th_ajaran',
                    displayField: 'tahun_ajaran',
                    typeAhead: true,
                    triggerAction: 'all',                    
                    allowBlank: false,
                    editable: false  
                    ,listeners:{
                        select:function(cmb,rec){
                                                                        console.log(rec[0].get('tahun_ajaran'));
                        }
                    }
                },{xtype: 'combo',                                                            
                    tooltip: 'Field tidak boleh kosong',
                    afterLabelTextTpl: required_css,
                    fieldLabel: 'Biaya', 
                    name:'kd_biaya',
                    //                                    fieldLabel: 'Jenis Biaya',                        
                    id: 'Ubis_kd_biaya',
                    mode:'local',
                    store: combobiayaStoreU,
                    valueField: 'kd_biaya',
                    displayField: 'keterangan',
                    typeAhead: true,
                    triggerAction: 'all',                    
                    allowBlank: false,
                    editable: false,                                
                    listeners: {
                        select:function( combo, records, eOpts ){
//                            var sexists=false;
//                            var vnis=Ext.getCmp('Ubis_nis').getValue();
//                            var vth=Ext.getCmp('Ubis_id_th_ajaran').getValue();
//                            biayasiswaStoreAll.each(function(node){                                
//                                if(node.data.kd_biaya==combo.getValue() && node.data.nis==vnis 
//                                    && node.data.id_th_ajaran==vth ){
//                                    sexists=true;
//                                }                                            
//                            });
//                            if(sexists){
//                                set_message(2, 'Kode Biaya Sudah Terdaftar !');
//                                combo.setValue('');
//                            }else{
//                                var rec=records[0];
////                                Ext.getCmp('Ubis_kd_biaya').setValue(rec.get('kd_biaya'));
//                                Ext.getCmp('Ubis_biaya_dasar').setValue(rec.get('biaya_dasar'));
//                                Ext.getCmp('Ubis_biaya_dikenakan').setValue(rec.get('biaya_dasar'));
//                                Ext.getCmp('Ubis_biaya_dikenakan').focus();
//                            }   
                        }
                    }
                }
                ,{
                    xtype:'numericfield',                                
                    fieldLabel:'Biaya Dasar',
                    name:'biaya_dasar',
                    id: 'Ubis_biaya_dasar',
                    allowBlank: false,                                                                        
                    hideTrigger: true,
                    fieldStyle: 'text-align: right;',
                    minValue: 0                                                                                         
                    ,readOnly:true,
                    currencySymbol: null,
                    useThousandSeparator: true,
                    thousandSeparator: ',',
                    alwaysDisplayDecimals: false
                }
                ,{
                    xtype:'numericfield',                                
                    name:'biaya_dikenakan',
                    fieldLabel:'Biaya Dikenakan',
                    id: 'Ubis_biaya_dikenakan',
                    allowBlank: false,                                                                        
                    hideTrigger: true,
                    fieldStyle: 'text-align: right;',
                    minValue: 0,      
                    currencySymbol: null,
                    useThousandSeparator: true,
                    thousandSeparator: ',',
                    alwaysDisplayDecimals: false
                }
                                
                    
                
            ];
            this.buttons = [
                {
                    text: 'Simpan',                    
                    itemId: 'simpan',
                    id:'btn_Ubis_simpan',
                    iconCls: 'icons-add',
                    formBind: true,
                    scope: this,
                    handler: this.submit
                },
                {
                    text: 'Batal',
                    action: 'cancel',
                    itemId: 'batal',
                    iconCls: 'cancel',
                    handler: function(){
                        this.up('window').close();
                    }
                }
            ];
            this.callParent(arguments);
        },
        submit: function(){
            var parcmd=Ext.getCmp('btn_Ubis_simpan').getText();
            var mbiaya_dikenakan=0;var mbiaya_dasar=0;
            if(parcmd === 'Simpan'){
                parcmd='insert';
            }else if(parcmd === 'Edit'){
                parcmd='update';
               
            }
             mbiaya_dikenakan=Ext.getCmp('Ubis_biaya_dikenakan').getValue();
             mbiaya_dasar=Ext.getCmp('Ubis_biaya_dasar').getValue();
            Ext.getCmp('FormUbis_id').getForm().submit({
                url: this.url,
                scope: this,                               
                params: {
                    cmd: parcmd,
                    mbiaya_dikenakan:mbiaya_dikenakan,
                    mbiaya_dasar:mbiaya_dasar
                },
                waitMsg: 'Saving Data...',
                success: function(form, action) {                    
                    set_message(0,action.result.msg);                    
                    Ext.getCmp('gridbiayasiswa').store.reload(); 
                    Ext.getCmp('FormUbis_id').getForm().reset();
                    Ext.getCmp('WindowUbis_id').close();
                },
                failure: function(form, action) {
                    if(action.result.msg=='Session Expired') {
                        session_expired(action.result.msg);
                    }else{
                        set_message(1, action.result.msg);
                    }
                                            
                    
                }
            });
        },
        showError: function(msg, title){
            title = title || 'Error';
            Ext.Msg.show({
                title: title,
                msg: msg,
                modal: true,
                icon: Ext.Msg.ERROR,
                buttons: Ext.Msg.OK,
                fn: function(btn){
                    if (btn == 'ok' && msg == 'Session Expired') {
                        window.location = '<?= site_url("auth/login") ?>';
                    }
                }
            });
        }
    });
    
    
    
    Ext.define('WindowUbis', {
        extend          : 'Ext.window.Window',
        title           : 'Form Edit Biaya Siswa',
        width           : 400,
        height          : 300,
        layout          : 'fit',
        autoShow        : true,
        modal           : true,
        alias           : 'widget.ubisEdit',
        id              : 'WindowUbis_id',
        initComponent   : function(){
            this.items = [
                Ext.widget('UbisForm')
            ];
            this.callParent(arguments);
        }

    });
    
    
    //===================
    Ext.define('MyTabBiayaSiswa', {
        extend: 'Ext.container.Container',
        xtype: 'TabBiayaSiswa',
        alias: 'widget.TabBiayaSiswa',
        title: 'Biaya Siswa',
        id: 'tab9',
        closable: true,        
        layout: 'border',
        items: [
            {
                xtype: 'panel',
                autoShow: true,
                id: 'panelbiayasiswa',            
                region: 'center',
                margins: '5 5 5 5',
                layout: 'fit',
                items:[
                    {
                        xtype:'grid',
                        id:'gridbiayasiswa',
                        stateful:true,
                        stateId:'stateGridbiayasiswa',
                        store: biayasiswaStoreGroup,//Ext.data.StoreManager.lookup('mMasterAccountStore'),
                        stripeRows: true,
                        loadMask: true
                        //                        ,plugins: [Ext.create('Ext.ux.grid.plugin.GroupingPanel')]
                        //                        ,                        
                        //                        sm:sm_masteraccount,
                        ,columns:[
                            {
                                header: 'Edit/Delete',
                                menuDisabled: true,
                                sortable: false,
                                xtype: 'actioncolumn',
                                width: 70,
                                align:'center',
                                items: [
                                    {
                                        iconCls: 'icon-edit-record',
                                        tooltip: 'Edit Row',
                                        handler: function(grid, rowIndex, colIndex) {
                                            var rec = grid.getStore().getAt(rowIndex);
                                            var winUbis=Ext.create('WindowUbis');
                                            winUbis.setTitle('Edit Form');
                                            biayasiswaStoreAll.load();
                                            Ext.getCmp('btn_Ubis_simpan').setText('Edit');
                                            Ext.getCmp('btn_Ubis_simpan').setIconCls('icon-edit-record');
                                            Ext.getCmp('Ubis_id').setReadOnly(true);
                                            Ext.getCmp('Ubis_id').setFieldStyle('readonly-input');
                                            Ext.getCmp('Ubis_nis').setReadOnly(true);
                                            Ext.getCmp('Ubis_nis').setFieldStyle('readonly-input');
                                            Ext.getCmp('Ubis_nama').setReadOnly(true);
                                            Ext.getCmp('Ubis_nama').setFieldStyle('readonly-input');
                                            Ext.getCmp('Ubis_kelas').setReadOnly(true);
                                            Ext.getCmp('Ubis_kelas').setFieldStyle('readonly-input');
                                            Ext.getCmp('Ubis_id_th_ajaran').setReadOnly(true);
                                            Ext.getCmp('Ubis_id_th_ajaran').setFieldStyle('readonly-input');
                                            Ext.getCmp('Ubis_kd_biaya').setReadOnly(true);
                                            Ext.getCmp('Ubis_kd_biaya').setFieldStyle('readonly-input');
                                            Ext.getCmp('Ubis_id_th_ajaran').setValue(rec.get('id_th_ajaran'));
                                            Ext.getCmp('Ubis_id').setValue(rec.get('id')); 
                                            Ext.getCmp('Ubis_nis').setValue(rec.get('nis')); 
                                            Ext.getCmp('Ubis_nama').setValue(rec.get('nama')); 
                                            Ext.getCmp('Ubis_kelas').setValue(rec.get('kelas')); 
                                            Ext.getCmp('Ubis_kd_biaya').setValue(rec.get('kd_biaya')); 
                                            Ext.getCmp('Ubis_biaya_dasar').setValue(rec.get('biaya_dasar')); 
                                            Ext.getCmp('Ubis_biaya_dikenakan').setValue(rec.get('biaya_dikenakan')); 
                                                                                                                                 
                                            winUbis.show();
                                        }
                                    },{
                                        getClass: function(v, meta, rec) {
                                            return 'icon-delete';
                                        },
                                        getTip: function(v, meta, rec) {
                                            return 'Delete Plant';
                                        },
                                        handler: function(grid, rowIndex, colIndex) {
                                            var rec = grid.getStore().getAt(rowIndex);
                                            console.log(rec.data);
                                            //                                            Ext.Msg.alert('Delete', 'Delete ' + rec.get('rekening'));
                                            Ext.Msg.show({
                                                title: 'Confirm',
                                                msg: 'Are you sure delete selected row ?',
                                                buttons: Ext.Msg.YESNO,
                                                icon: Ext.Msg.QUESTION,
                                                fn: function(btn){
                                                    if (btn == 'yes') {
                    
                                                        var data = '';
                                                        data = Ext.JSON.encode(rec.data);
                        
                                                        Ext.Ajax.request({                                                            
                                                            url: '<?php echo base_url(); ?>' +'biayasiswa/delete_row',
                                                            method: 'POST',
                                                            params: {
                                                                cmd: 'delete',
                                                                postdata: data
                                                            },
                                                            success: function(obj) {
                                                                var   resp = Ext.decode(obj.responseText);                                                                
                                                                if(resp.success==true){
                                                                    //                                                                    Ext.Msg.alert('info',resp.msg);
                                                                    set_message(0,resp.msg);
                                                                    Ext.getCmp('gridbiayasiswa').store.reload();                                                                                                                                     
                                                                }else{
                                                                    Ext.Msg.show({
                                                                        title: 'Error',
                                                                        msg: resp.msg,
                                                                        modal: true,
                                                                        icon: Ext.Msg.ERROR,
                                                                        buttons: Ext.Msg.OK,
                                                                        fn: function(btn){
                                                                            if (btn == 'ok' && resp.msg == 'Session Expired') {
                                                                                window.location = '<?= site_url("auth/login") ?>';
                                                                            }
                                                                        }
                                                                    });
                                                                }
                                                            },
                                                            failure: function(obj) {
                                                                var  resp = Ext.decode(obj.responseText);
                                                                set_message(0, resp.reason);
                                                                //                                                                Ext.Msg.alert('info',resp.reason);
                                                            }                                                            
                                                        });                 
                                                    } 
                                                }
                                            });
                                        }
                                    }
                                ]
                            }
                           
                            ,
                            
                            
                            {
                                header: "NIS",
                                dataIndex: 'nis',
                                sortable: true,
                                width: 100,
                                //                                groupable:      true,groupHeaderTpl: '{name}',
                                align:'center'
                                ,hidden:true
                                
                            }
                            ,{
                                header: "Nama Siswa",
                                dataIndex: 'nama',
                                sortable: true,
                                width: 120      
                                ,hidden:true
                            }
                            ,{
                                header: "kd_kelas",
                                dataIndex: 'kd_kelas',
                                sortable: true,
                                width: 50     
                                ,align:'center'
                                ,hidden:true
                            }
                            ,{
                                header: "Kelas",
                                dataIndex: 'kelas',
                                sortable: true,
                                width: 80     
                                ,align:'center'
                                ,hidden:true
                            }
                            ,{
                                header: "id_tahun_ajaran",
                                dataIndex: 'id_tahun_ajaran',
                                sortable: true
                                //                                ,groupable:      true,groupHeaderTpl: '{name}'
                                ,width: 50     
                                ,align:'center'
                                
                                ,hidden:true
                            }
                            ,{
                                header: "Tahun Ajaran",
                                dataIndex: 'tahun_ajaran',
                                sortable: true,
                                width: 80     
                                ,align:'center'
                                ,hidden:true
                            }
                            ,{
                                header: "Kode Biaya",
                                dataIndex: 'kd_biaya',
                                sortable: true,
                                width: 80     
                                ,align:'center'
                                //                                ,hidden:true
                            }
                            ,{
                                header: "Biaya",
                                dataIndex: 'biaya',
                                sortable: true,
                                width: 120     
                                //                                ,align:'center'
                            }
                            ,{
                            xtype:'numbercolumn',
                                header: "Biaya Dasar",
                                dataIndex: 'biaya_dasar',
                                sortable: true,
                                width: 100     
                                ,align:'right'
                                ,format:'0,0'
                            }
                            ,{
                            xtype:'numbercolumn',
                                header: "Biaya Dikenakan",
                                dataIndex: 'biaya_dikenakan',
                                sortable: true,
                                width: 100     
                                ,align:'right'
                                ,format:'0,0'
                            }
                            ,{
                                header: "Tanggal Entry",
                                dataIndex: 'tgl_entri',
                                sortable: true,
                                width: 120     
                                ,align:'center'
                                
                            }
                            ,{
                                header: "User Entry",
                                dataIndex: 'id_user',
                                sortable: true,
                                width: 80     
                                ,align:'left'
                                
                            }
                        ]
                        ,tbar:{
                            xtype: 'toolbar',
                            padding:'2 0 2 5',
                            items: [
                                {
                                    xtype: 'button',
                                    text: 'Add',
                                    iconCls: 'icons-add',
                                    onClick: function()
                                    {
                                        allsiswaStoreBi.load();
                                        entrybiayasiswaStore.removeAll();
                                        var winbisiswa=Ext.create('Windowbiayasiswa');
                                        winbisiswa.setTitle('Add Form');
                                        Ext.getCmp('btn_biayasiswa_simpan').setText('Simpan');
                                        Ext.getCmp('btn_biayasiswa_simpan').setIconCls('icons-add');
                                        //                                        //                                        setDefaultStoreProxy(KelompokAccountStore, urlKelompok);
                                        winbisiswa.show();
                                    } 
                                },
                                '-',
                                {
                                    width: 300,
                                    //                                fieldLabel: 'Search',
                                    //                                labelWidth: 50,
                                    xtype: 'searchfield',
                                    store: biayasiswaStoreGroup,
                                    emptyText: 'Quick Search...'
                                }
                            ]
                        }
                        ,bbar:{                        
                            xtype: 'pagingtoolbar',
                            store: biayasiswaStoreGroup,pageSize: ENDPAGE,
                            displayInfo: true
                            //                    plugins: Ext.create('Ext.ux.SlidingPager', {})
                        }
                        
                        ,features:[ {
                                ftype: 'grouping',
                                //                                groupHeaderTpl: '{columnName}: {name} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})',
                                groupHeaderTpl: '{name}',
                                hideGroupedHeader: true,
                                startCollapsed: false,
                                id: 'bis_grid_Grouping'
                            }]
                    }
                ]
            }
        ]
        ,
        listeners:{
            show:function(){
                var storegrid=Ext.getCmp('gridbiayasiswa').store;                
                storegrid.loadPage(1);
                biayasiswaStoreAll.load();
                combobiayaStoreU.load();
                combothajaranStoreU.load();
                //                comboKelasStore.load();
               
            }
        }
        , initComponent: function() {
            this.callParent(arguments);
        }
    });
</script>
